var express = require('express');
var router = express.Router();
const connection = require('../database/mysql')
const path = require('path')
const sql = require('../routehandles/mysqlhandle');
const { request } = require('http');

router.post('/search',async function(req,res)
{
    var params = req.body
    if(params.key == '' || params.key == null)
    {
        return res.json({msg:'请输入要查询的内容',result:'false'})
    }else 
    {
        // var a = await sql.sPublishTableByNickname(params.key)
        var a = await sql.sPublishTableById2(params.key)
        // var c = await sql.sPublishTableByTag(params.key)
        // console.log(a)
        // console.log(typeof(a))
        return res.json({a,result:'true'})
    }
})
router.post('/getUserinfo',async (req,res)=>{
    var params = req.body
    var result = await sql.sUAPTable(params.username)
    var a = result
    return res.json({a,result:'true'})
  })
router.post('/getNickname',async function(req,res)
{
    var params = req.body
    var aa =  await sql.sUAPTable(params.username)
    return res.json({aa,result:'true'})
})
router.post('/searchAll',async function(req,res)
{
    var params = req.body
    
        // var a = await sql.sPublishTableByNickname(params.key)
        var a = await sql.sPublishTableAll2()
        // var c = await sql.sPublishTableByTag(params.key)
        // console.log(a)
        // console.log(typeof(a))
        return res.json({a,result:'true'})
    
})
router.post('/searchByTag',async function(req,res)
{
    var params = req.body
    if(params.key == '' || params.key == null)
    {
        console.log('2333')
        return res.json({msg:'请输入要查询的内容',result:'false'})
    }else 
    {
        // var a = await sql.sPublishTableByNickname(params.key)
        // var a = await sql.sPublishTableById(params.key)
        var a = await sql.sPublishTableByTag(params.key)
        // console.log(a)
        // console.log(typeof(a))
        return res.json({a,result:'true'})
    }
})
router.post('/searchByNickname',async function(req,res)
{
    var params = req.body
    if(params.key == '' || params.key == null)
    {
        console.log('2333')
        return res.json({msg:'请输入要查询的内容',result:'false'})
    }else 
    {
        var a = await sql.sPublishTableByNickname(params.key)
        // var a = await sql.sPublishTableById(params.key)
        // var c = await sql.sPublishTableByTag(params.key)
        // var a = await sql.sPublishTableByUsername(params.key)
        // console.log(a)
        // console.log(typeof(a))
        return res.json({a,result:'true'})
    }
})

module.exports = router